//获取值或者更新原来的旧值
function updateGetInfo(key, value) {
	//如果value的值如if中所示，说明这是取值行为，将返回key值所对应的值
	//数组，对象，布尔先使用JSON转换成json字符串
	if(localStorage.length > 0) {
		for(var i = 0; i < localStorage.length; i++) {
			//key值相同，说明是更新值
			if(localStorage.key(i).indexOf("{") > -1) {
				if(JSON.parse(localStorage.key(i)) instanceof Object) {
					if(JSON.parse(localStorage.key(i)).day <= (new Date().getTime())) {
						localStorage.removeItem(localStorage.key(i));
					} else {
						if(key == JSON.parse(localStorage.key(i)).name) {
							if(value == undefined || value == null || value == "") {
								return JSON.parse(localStorage.getItem(localStorage.key(i)));
							} else {
								localStorage.setItem(localStorage.key(i), JSON.stringify(value));
								return true; //返回true，说明更新值成功
							}
						} else {
							return false; //返回false，说明在存储的数据中没有该key值，无法修改
						}
					}
				}
			} else {
				if(key == localStorage.key(i)) {
					if(value == undefined || value == null || value == "") {
						return JSON.parse(localStorage.getItem(key));
					} else {
						localStorage.setItem(key, JSON.stringify(value));
						return true; //返回true，说明更新值成功
					}
				} else {
					return false; //返回false，说明在存储的数据中没有该key值，无法修改
				}
			}
		}
	}
}

//设置新值
function setInfo(key, value, day) {
	//设置新值的时候可以传入对象，数组，单个的key
	//	localStorage.setItem(key,JSON.stringify(value));
	if(day) {
		console.log(111);
		var date = new Date().getTime();
		var time = day * 24 * 60 * 60 * 1000 + date;
		var obj = {
			"name": key,
			"day": time
		};
		localStorage.setItem(JSON.stringify(obj), JSON.stringify(value));
	} else {
		localStorage.setItem(key, JSON.stringify(value));
	}
}

//删除
function deleteInfo(key) {
	//key值可以是单值，也可以是一个数组
	if(key != undefined && key != null & key != "") {
		if(key instanceof Array) {
			if(localStorage.length > 0) {
				for(var i in key) {
					for(var j in localStorage) {
						if(key[i] == JSON.parse(localStorage.key(j)).name) {
							localStorage.removeItem(localStorage.key(j));
						}
					}
				}
				return true;
			} else {
				return false;
			}
		} else if("string" == typeof key) {
			for(var j in localStorage) {
				if(key == JSON.parse(localStorage.key(j)).name) {
					localStorage.removeItem(localStorage.key(j));
				}
			}
		}
	} else {
		localStorage.clear();
	}
}